package com.example.demo.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpStatus;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@Controller
@RequestMapping("login")
public class LoginController {

	// 原请求信息的缓存及恢复
    private RequestCache requestCache = new HttpSessionRequestCache();
	
	@RequestMapping("/")
	@ResponseStatus(code = HttpStatus.UNAUTHORIZED)
	@ResponseBody
	public Object login(HttpServletRequest request, HttpServletResponse response) {
		SavedRequest request2 = requestCache.getRequest(request, response);
		String redirectUrl = request2.getRedirectUrl();
		Map<String, String[]> parameterMap = request2.getParameterMap();
		return parameterMap;
	}
}
